@@ -1,5 +1,5 @@ |
||
| 1 | 1 |
class MigrateHipchatAndEfAgentToLiquid < ActiveRecord::Migration |
| 2 |
- def change |
|
| 2 |
+ def up |
|
| 3 | 3 |
Agent.where(:type => 'Agents::HipchatAgent').each do |agent| |
| 4 | 4 |
LiquidMigrator.convert_all_agent_options(agent) |
| 5 | 5 |
end |
@@ -8,4 +8,8 @@ class MigrateHipchatAndEfAgentToLiquid < ActiveRecord::Migration |
||
| 8 | 8 |
agent.save |
| 9 | 9 |
end |
| 10 | 10 |
end |
| 11 |
+ |
|
| 12 |
+ def down |
|
| 13 |
+ raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating" |
|
| 14 |
+ end |
|
| 11 | 15 |
end |
@@ -1,7 +1,11 @@ |
||
| 1 | 1 |
class MigratePushbulletAgentToLiquid < ActiveRecord::Migration |
| 2 |
- def change |
|
| 2 |
+ def up |
|
| 3 | 3 |
Agent.where(:type => 'Agents::PushbulletAgent').each do |agent| |
| 4 | 4 |
LiquidMigrator.convert_all_agent_options(agent) |
| 5 | 5 |
end |
| 6 | 6 |
end |
| 7 |
+ |
|
| 8 |
+ def down |
|
| 9 |
+ raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating" |
|
| 10 |
+ end |
|
| 7 | 11 |
end |
@@ -1,7 +1,11 @@ |
||
| 1 | 1 |
class MigrateJabberAgentToLiquid < ActiveRecord::Migration |
| 2 |
- def change |
|
| 2 |
+ def up |
|
| 3 | 3 |
Agent.where(:type => 'Agents::JabberAgent').each do |agent| |
| 4 | 4 |
LiquidMigrator.convert_all_agent_options(agent) |
| 5 | 5 |
end |
| 6 | 6 |
end |
| 7 |
+ |
|
| 8 |
+ def down |
|
| 9 |
+ raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating" |
|
| 10 |
+ end |
|
| 7 | 11 |
end |
@@ -1,7 +1,11 @@ |
||
| 1 | 1 |
class MigrateDataOutputAgentToLiquid < ActiveRecord::Migration |
| 2 |
- def change |
|
| 2 |
+ def up |
|
| 3 | 3 |
Agent.where(:type => 'Agents::DataOutputAgent').each do |agent| |
| 4 | 4 |
LiquidMigrator.convert_all_agent_options(agent) |
| 5 | 5 |
end |
| 6 | 6 |
end |
| 7 |
+ |
|
| 8 |
+ def down |
|
| 9 |
+ raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating" |
|
| 10 |
+ end |
|
| 7 | 11 |
end |
@@ -1,8 +1,12 @@ |
||
| 1 | 1 |
class MigrateTranslationAgentToLiquid < ActiveRecord::Migration |
| 2 |
- def change |
|
| 2 |
+ def up |
|
| 3 | 3 |
Agent.where(:type => 'Agents::TranslationAgent').each do |agent| |
| 4 | 4 |
agent.options['content'] = LiquidMigrator.convert_hash(agent.options['content'], {:merge_path_attributes => true, :leading_dollarsign_is_jsonpath => true})
|
| 5 | 5 |
agent.save |
| 6 | 6 |
end |
| 7 | 7 |
end |
| 8 |
+ |
|
| 9 |
+ def down |
|
| 10 |
+ raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating" |
|
| 11 |
+ end |
|
| 8 | 12 |
end |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 |
class MigrateTwitterPublishAgentToLiquid < ActiveRecord::Migration |
| 2 |
- def change |
|
| 2 |
+ def up |
|
| 3 | 3 |
Agent.where(:type => 'Agents::TwitterPublishAgent').each do |agent| |
| 4 | 4 |
if (message = agent.options.delete('message_path')).present?
|
| 5 | 5 |
agent.options['message'] = "{{#{message}}}"
|
@@ -7,4 +7,8 @@ class MigrateTwitterPublishAgentToLiquid < ActiveRecord::Migration |
||
| 7 | 7 |
end |
| 8 | 8 |
end |
| 9 | 9 |
end |
| 10 |
+ |
|
| 11 |
+ def down |
|
| 12 |
+ raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating" |
|
| 13 |
+ end |
|
| 10 | 14 |
end |
@@ -52,11 +52,15 @@ module LiquidMigrator |
||
| 52 | 52 |
|
| 53 | 53 |
def self.convert_json_path(string, filter = "") |
| 54 | 54 |
check_path(string) |
| 55 |
- "{{#{string[2..-1]}#{filter}}}"
|
|
| 55 |
+ if string.start_with? '$.' |
|
| 56 |
+ "{{#{string[2..-1]}#{filter}}}"
|
|
| 57 |
+ else |
|
| 58 |
+ "{{#{string[1..-1]}#{filter}}}"
|
|
| 59 |
+ end |
|
| 56 | 60 |
end |
| 57 | 61 |
|
| 58 | 62 |
def self.check_path(string) |
| 59 |
- if string !~ /\A(\$\.)?(\w+\.)*(\w+)\Z/ |
|
| 63 |
+ if string !~ /\A(\$\.?)?(\w+\.)*(\w+)\Z/ |
|
| 60 | 64 |
raise "JSONPath '#{string}' is too complex, please check your migration."
|
| 61 | 65 |
end |
| 62 | 66 |
end |
@@ -5,10 +5,12 @@ describe LiquidMigrator do |
||
| 5 | 5 |
it "should work" do |
| 6 | 6 |
LiquidMigrator.convert_string("$.data", true).should == "{{data}}"
|
| 7 | 7 |
LiquidMigrator.convert_string("$.data.test", true).should == "{{data.test}}"
|
| 8 |
+ LiquidMigrator.convert_string("$first_title", true).should == "{{first_title}}"
|
|
| 8 | 9 |
end |
| 9 | 10 |
|
| 10 | 11 |
it "should ignore strings which just contain a JSONPath" do |
| 11 | 12 |
LiquidMigrator.convert_string("$.data").should == "$.data"
|
| 13 |
+ LiquidMigrator.convert_string("$first_title").should == "$first_title"
|
|
| 12 | 14 |
LiquidMigrator.convert_string(" $.data", true).should == " $.data"
|
| 13 | 15 |
LiquidMigrator.convert_string("lorem $.data", true).should == "lorem $.data"
|
| 14 | 16 |
end |